#include <bits/stdc++.h>
#define ll long long
using namespace std;

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while (ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar();
	while (ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int __stk[128], __top;
inline void write(ll x) {
    if(x < 0) putchar('-'), x = -x;
	do { __stk[++__top] = x % 10, x /= 10; } while (x);
	while (__top) putchar(__stk[__top--] + '0');
}

const int mod = 998244353;

void Min(int &x, int y) { y < x and (x = y); }
void Max(int &x, int y) { y > x and (x = y); }

void inc(int &x, int y) { (x += y) >= mod and (x -= mod); }
void mul(int &x, int y) { x = 1ll * x * y % mod; }

int q_pow(int x, int k) { int res = 1; for (; k; k >>= 1, mul(x, x)) if (k & 1) mul(res, x); return res; }

bool stmer;

const int N = 5e5 + 10;

int n, m, q;
int fa[N];

struct Node {
    int x, y;
} a[N];

struct node {
	int a, b, c, d;
} f[N];

set<pair<int, int>> t[2][N];

vector<int> p;

int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }

void find(int op, int x, int l, int r) {
	if (x < 1) return;
	while (1) {
		auto it = t[op][x].lower_bound({ l, 0 });
		if (it == t[op][x].end() or it -> first > r) return;
		p.push_back(it -> second), t[op][x].erase(it);
	}
}

void merge(int x, int y) {
	x = find(x), y = find(y);
	if (x ^ y) {
		fa[y] = x;
		Min(f[x].a, f[y].a), Max(f[x].b, f[y].b);
		Min(f[x].c, f[y].c), Max(f[x].d, f[y].d);
	}
}

void add(int x, int y, int id) {
	t[0][x].insert({ y, id });
	t[1][y].insert({ x, id });
}

void work(int id) {
	while (1) {
		p.clear();
		find(0, f[id].a - 1, f[id].c - 1, f[id].d + 1);
		find(0, f[id].b + 1, f[id].c - 1, f[id].d + 1);
		find(0, f[id].a - 2, f[id].c, f[id].d);
		find(0, f[id].b + 2, f[id].c, f[id].d);

		find(1, f[id].c - 1, f[id].a - 1, f[id].b + 1);
		find(1, f[id].d + 1, f[id].a - 1, f[id].b + 1);
		find(1, f[id].c - 2, f[id].a, f[id].b);
		find(1, f[id].d + 2, f[id].a, f[id].b);

		if (p.empty()) break;
		for (int x : p) merge(id, x);
	}

	for (int i = f[id].a; i <= f[id].b; i++) add(i, f[id].c, id), add(i, f[id].d, id);
	for (int i = f[id].c + 1; i < f[id].d; i++) add(f[id].a, i, id), add(f[id].b, i, id);
	// t[0][f[id].a].insert({ f[id].c, id }), t[0][f[id].a].insert({ f[id].d, id });
	// t[0][f[id].b].insert({ f[id].c, id }), t[0][f[id].b].insert({ f[id].d, id });
	// t[1][f[id].c].insert({ f[id].a, id }), t[1][f[id].c].insert({ f[id].b, id });
	// t[1][f[id].d].insert({ f[id].a, id }), t[1][f[id].d].insert({ f[id].b, id });
}

ll ans;

namespace SEG {
	#define ls (lr << 1)
	#define rs (lr << 1 | 1)
	#define mid ((l + r) >> 1)

	int t[N << 2], cnt[N << 2];

	vector<pair<pair<int, int>, int>> op[N];

	void modify(int l, int r, int L, int R, int k, int lr) {
		if (l >= L and r <= R) {
			cnt[lr] += k, t[lr] = cnt[lr] ? r - l + 1 : (t[ls] + t[rs]);
			return;
		}
		if (mid >= L) modify(l, mid, L, R, k, ls);
		if (mid < R) modify(mid + 1, r, L, R, k, rs);
		t[lr] = cnt[lr] ? r - l + 1 : (t[ls] + t[rs]);
	}

	void main() {
		for (int i = 1; i <= n; i++) {
			for (auto l : op[i]) modify(1, m, l.first.first, l.first.second, l.second, 1);
			ans += t[1];
		}
	}
}

bool edmer;
signed main() {
	freopen("grid.in", "r", stdin);
	freopen("grid.out", "w", stdout);
	cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n";
    
    n = read(), m = read(), q = read();

    for (int i = 1; i <= q; i++) {
		a[i] = { read(), read() }, fa[i] = i;
		t[0][a[i].x].insert({ a[i].y, i });
		t[1][a[i].y].insert({ a[i].x, i });
		f[i] = { a[i].x, a[i].x, a[i].y, a[i].y };
	}

	for (int i = 1; i <= n; i++) if (i == find(i)) work(i);

	for (int i = 1; i <= n; i++) if (find(i) == i) {
		SEG :: op[f[i].a].push_back({ { f[i].c, f[i].d }, 1 });
		SEG :: op[f[i].b + 1].push_back({ { f[i].c, f[i].d }, -1 });
	}

	SEG :: main();
	
	write(ans), putchar('\n');

    cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds\n";
	return 0;
} 